﻿Public Class Main_Screen

    Private WithEvents _ctrl As Main_CTRL



#Region "Cycle de Vie fenêtre principale"

    ''' <summary>
    ''' Constructeur surchargé de la fenêtre principale
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

        ' Cet appel est requis par le Concepteur Windows Form.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        _ctrl = New Main_CTRL
    End Sub

    ''' <summary>
    ''' Action effectuées au chargement de la fenêtre principale
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Main_Screen_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        VéterinaireToolStripMenuItem.Enabled = False


    End Sub

    ''' <summary>
    ''' Action effectuées à la fermeture/suppression de la fenêtre principale
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Main_Screen_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed



    End Sub

#End Region


    'TODO On pourrait peut-etre gerer ca avec des évenements : prise en charge groupée 
    'des clicks de la listview et du menustrip (ou pas)
    ''' <summary>
    ''' Au clic sur un element de la listview lancement de la procedure d'affichage appropriée
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub LVWmain_MouseClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LVWmain.MouseClick
        Try
            Select Case LVWmain.FocusedItem.Index

                Case 0 'Rendez-Vous
                    Affichage(New RendezVous_Screen(_ctrl.getRendezVous_CTRL))
                Case 1 'Clients/Animaux
                    Affichage(New Client_Screen(_ctrl.getClient_CTRL))
                Case 2 'Relance
                    Affichage(New Relance_Screen(_ctrl.getRelance_CTRL))
                Case 3 'Agendas
                    If _ctrl.vetoIdentifie IsNot Nothing Then
                        Affichage(New Agenda_Screen(_ctrl.GetAgenda_CTRL))
                    Else
                        MessageBox.Show("Il faut se connecter pour acceder à la page agendas (parametrage veterinaire)", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    End If
                Case 4 'Dossier Medical
                    If _ctrl.vetoIdentifie IsNot Nothing Then
                        Affichage(New ChoixDossierMedical_Screen(_ctrl.getChoixDossierMedical_CTRL))
                    Else
                        MessageBox.Show("Il faut se connecter pour acceder à la page dossier medical (parametrage veterinaire)", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    End If
                Case 5 'Quitter
                    Dim dialogresult As DialogResult = MessageBox.Show("Êtes-vous sûr?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
                    If dialogresult = Windows.Forms.DialogResult.Yes Then
                        Me.Close()
                    End If
            End Select
        Catch ex As Exception
            ErrorBox(ex)
        End Try
    End Sub

    ''' <summary>
    ''' Procedure d'affichage des fenetres fille
    ''' a chaque nouvelle affichage on supprime les fenetres ouvertes
    ''' </summary>
    ''' <param name="fenetre">parametre fenetre de type form</param>
    ''' <remarks></remarks>
    Private Sub Affichage(ByVal fenetre As Form)

        fenetre.MdiParent = Me
        Me.SplitContainerMAIN.Panel2.Controls.Clear()
        Me.SplitContainerMAIN.Panel2.Controls.Add(fenetre)
        fenetre.Dock = DockStyle.Fill
        fenetre.Show()

    End Sub

    ''' <summary>
    ''' Affichage de la fenetre rendez vous
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub PriseDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PriseDeToolStripMenuItem.Click
        Affichage(New RendezVous_Screen(_ctrl.getRendezVous_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre dossier client
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub DossiersClientsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DossiersClientsToolStripMenuItem.Click
        Affichage(New Client_Screen(_ctrl.getClient_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre relance
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub RelanceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RelanceToolStripMenuItem.Click
        Affichage(New Relance_Screen(_ctrl.getRelance_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre vaccins
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub MiseÀJourDuStockDeVaccinToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiseÀJourDuStockDeVaccinToolStripMenuItem.Click
        Affichage(New StockVaccins_Screen(_ctrl.getStockVaccins_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre agenda
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub AgendaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AgendaToolStripMenuItem.Click
        Affichage(New Agenda_Screen(_ctrl.GetAgenda_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre dossier medical
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub DossiersMédicauxToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DossiersMédicauxToolStripMenuItem.Click
        Affichage(New ChoixDossierMedical_Screen(_ctrl.getChoixDossierMedical_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre veterinaire
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub VétérinairesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VétérinairesToolStripMenuItem.Click
        Affichage(New Veterinaire_Screen(_ctrl.getVeterinaire_CTRL))
    End Sub

    ''' <summary>
    ''' Affichage de la fenetre bareme
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub MiseÀJourDuBarèmeDeNotificationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiseÀJourDuBarèmeDeNotificationToolStripMenuItem.Click
        Affichage(New Baremes_Screen(_ctrl.getBaremes_CTRL))
    End Sub

    ''' <summary>
    ''' Procédure gérant l'affichage dse erreurs
    ''' </summary>
    ''' <param name="ex"></param>
    ''' <remarks></remarks>
    Private Sub ErrorBox(ByVal ex As Exception)
        Dim _message As String = ex.Message
        If ex.InnerException IsNot Nothing Then
            _message &= vbCrLf & "Raison : " & ex.InnerException.Message
        End If
        MessageBox.Show(Me, _message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Sub


    Private Sub _ctrl_loginChanged(ByVal sender As Object, ByVal e As EventArgs) Handles _ctrl.loginChanged

        If _ctrl.vetoIdentifie IsNot Nothing Then

            VéterinaireToolStripMenuItem.Enabled = True
            VéterinaireToolStripMenuItem.ToolTipText = "menu veterinaires"


        Else

            VéterinaireToolStripMenuItem.Enabled = False
            VéterinaireToolStripMenuItem.ToolTipText = "Il faut être connecté pour acceder au menu veterinaires"

        End If

    End Sub
End Class